package com.higgins.eventtracking.server.dataModel;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.higgins.eventtracking.client.dto.FinanceGoalDTO;
import com.higgins.eventtracking.client.dto.GoalDTO;
import com.higgins.eventtracking.client.dto.RuleDTO;

@PersistenceCapable
public class Rule {
	@SuppressWarnings("unused")
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	
	@Persistent
	private String task;
	
    @Persistent
    private String parentDynamicType;

    @Persistent
    private String frameOfMind;

	@Persistent
	private Date timestamp;
	
	@Persistent
	private Integer intensity;
	
	@Persistent
	private Integer order;
	
	
	public Rule(RuleDTO dto)	{
		this.task = dto.getTask();
		this.parentDynamicType = dto.getParentDynamicType();
		this.frameOfMind = dto.getFrameOfMind();
		this.timestamp = dto.getTimestamp();
		this.intensity = dto.getIntensity();
		this.order = dto.getOrder();
	}
	public Rule()	{
		timestamp = new Date();
	}
	public void setId(Long id)	{
		this.id = id;
	}
	public Long getId()	{
		return id;
	}
	public void setTask(String task)	{
		this.task = task;
	}
	public String getTask()	{
		return task;
	}
    public void setParentDynamicType(String parentDynamicType) {
        this.parentDynamicType = parentDynamicType;
    }
    public String getParentDynamicType()    {
        return parentDynamicType;
    }
	public void setFrameOfMind(String frameOfMind)	{
		this.frameOfMind = frameOfMind;
	}
	public String getFrameOfMind()	{
		return frameOfMind;
	}
	public void setTimestamp(Date timestamp)	{
		this.timestamp = timestamp;
	}
	public Date getTimestamp()	{
		return timestamp;
	}
	public RuleDTO toDTO()	{
		RuleDTO ruleDTO = new RuleDTO();
		ruleDTO.setId(id);
		ruleDTO.setTask(task);
		ruleDTO.setParentDynamicType(parentDynamicType);
		ruleDTO.setFrameOfMind(frameOfMind);
		ruleDTO.setTimestamp(timestamp);
		ruleDTO.setIntensity(intensity);
		ruleDTO.setOrder(order);
		return ruleDTO;
	}
	public void update(RuleDTO dto)	{
		this.task = dto.getTask();
		this.parentDynamicType = dto.getParentDynamicType();
		this.frameOfMind = dto.getFrameOfMind();
		this.timestamp = dto.getTimestamp()!=null?dto.getTimestamp():new Date();
		this.intensity = dto.getIntensity();
		this.order = dto.getOrder();
	}
}
